﻿using System;
using System.Collections.Generic;
using System.Linq;
using Changeset = TfsCommitMonitor.Tfs.Changeset;

namespace TfsCommitMonitor.Tests.Mocking
{
	class MockTfsPoller
	{
		private String _projectPath;
		public Changeset[] PollForChanges(Int32? lastChangesetId, String projectPath = "$/Fake/")
		{
			_projectPath = projectPath;
			return
				TestData
				.OrderByDescending(changeset => changeset.ChangesetId)
				.Take(lastChangesetId == null ? Configuration.Instance.MaxNumberOfChangesetsOnInitialLoad : 1000)
				.Where(changeset => lastChangesetId == null || changeset.ChangesetId > lastChangesetId)
				.ToArray();
		}

		private IEnumerable<Changeset> TestData
		{
			get
			{
				for (int i = 1; i < 100; i++)
				{
					yield return
						new Changeset
						{
							CollectionUri = new Uri("http://sv-fake:8080/tfs/Collection"),
							Changes = new[] { String.Format("{0}File{1}.txt", _projectPath, i), },
							ChangesetId = i,
							Comment = "Checked in Fix",
							Committor = @"Dave Shaw",
							CreationDate = DateTime.Now.Subtract(new TimeSpan(15 - i, 0, 0, 0, 0)),
							ProjectPath  = _projectPath,
							Read = false,
						};
				}
			}
		}
	}
}